<template>
  <div id="allOrders">
    <!--条件查询-->
    <el-form :inline="true" :model="searchObj" ref="SupplierList" class="demo-form-inline">
      <el-form-item label="订单编号">
        <el-input v-model="searchObj.orderNumber" placeholder="请输入订单号"></el-input>
      </el-form-item>
      <el-form-item label="订单进度">
        <el-select v-model="searchObj.conveyTag" placeholder="请选择" clearable>
          <el-option
              v-for="item in conveyTag"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
            v-model="searchObj.createTime"
            type="datetimerange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['23:00:00', '23:00:00']">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryBtn">查询</el-button>
        <el-button @click="">
          <i class="el-icon-refresh-right"></i>
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <!--数据表格-->
    <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
    >
      <el-table-column
          prop="orderNumber"
          label="订单编号">
      </el-table-column>
      <el-table-column
          label="下单用户(账号)">
        <template slot-scope="scope">
          <span>{{ scope.row.nickName +"("+ scope.row.userName +")" }}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="totalPrice"
          label="总金额">
      </el-table-column>
      <el-table-column
          prop="shopName"
          label="接单商户">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="下单时间">
      </el-table-column>

      <el-table-column
          label="订单进度">
        <template slot-scope="scope">
          <span v-if="scope.row.conveyTag== 'P001-1'">待付款</span>
          <span v-else-if="scope.row.conveyTag== 'P001-2'" style="color: darkorange">待发货</span>
          <span v-else-if="scope.row.conveyTag== 'P001-3'" style="color: blue">待收货</span>
          <span v-else-if="scope.row.conveyTag== 'P001-7'" style="color: blue">待提货</span>
          <span v-else-if="scope.row.conveyTag== 'P001-5'" style="color: green">已完成</span>
          <span v-else-if="scope.row.conveyTag== 'P001-6'" style="color: black">已取消</span>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="pageSizeList"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "AllOrders",
  data() {
    return {
      //查询条件
      searchObj: {},
      //订单进度下拉框
      conveyTag: [
        {
          value: "",
          label: '全部'
        },
        {
          value: "P001-2",
          label: '待发货'
        },
        {
          value: "P001-3",
          label: '待收货'
        },
        {
          value: "P001-7",
          label: '待提货'
        },
        {
          value: "P001-5",
          label: '已完成'
        },
        {
          value: "P001-6",
          label: '已取消'
        },
      ],
      //下单时间快捷提示
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 5,
      // 总记录数
      total: 10,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      // 返回数据对象
      tableData: [],
    }
  },
  methods: {
    //查询
    async queryBtn() {
      const { data: res } = await this.$http.post(`/orderInfo/getOrderList/${this.currentPage}/${this.pageSize}`,this.searchObj);
      this.tableData = res.rows;
      this.total = res.total;
    },
    //页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.queryBtn()
    },
    //当前页改变
    handleCurrentChange(val){
      this.currentPage = val
      this.queryBtn()
    },
  },
  created() {
    this.queryBtn();
  }
}
</script>

<style scoped>

</style>